import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

public class FibonacciPanel extends JPanel
{
	private Block xBlock = new Block(0, 0, 1, 0);
	private Block yBlock = new Block(0, 0, 1, 0);
	Fibonacci f = new Fibonacci();

	@Override
	public void paint(Graphics g)
	{		
		g.setColor(Color.RED);

		for (int i = 1; i <= 10; i++)
		{
			int fib = f.getFibonacciValue(i);

			if (i % 4 == 0)
				calcNextXBlock(i);
			
			if (i % 4 == 1 && i != 1)
				calcNextYBlock(i);

			g.drawRect(xBlock.getValueAt(i + 1), yBlock.getValueAt(i), fib, fib);
		}

	}

	private void calcNextYBlock(int n)
	{
		yBlock.setOne(yBlock.getValueAt(1) + (f.getFibonacciValue(n) * -1));
		yBlock.setTwo(yBlock.getValueAt(1));
		yBlock.setThree(f.getFibonacciValue(n-3));
		yBlock.setFour(yBlock.getValueAt(1));
	}

	private void calcNextXBlock(int n)
	{
		xBlock.setOne(xBlock.getValueAt(1) + (f.getFibonacciValue(n) * -1));
		xBlock.setTwo(xBlock.getValueAt(1));
		xBlock.setThree(f.getFibonacciValue(n-1) + xBlock.getValueAt(n-1));
		xBlock.setFour(xBlock.getValueAt(1));
		
	}
}
